-
-
Notifications
You must be signed in to change notification settings - Fork 238
/
[...slug].tsx
46 lines (41 loc) 路 1.05 KB
/
[...slug].tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import { GetStaticPaths, GetStaticProps } from "next";
import { DocLayout } from "~/components/layouts";
import MDXRenderer from "~/components/MDXRenderer";
import { getSlugs, getAllDocs, getDocBySlug, getDocsNav } from "~/lib/mdx";
export const getStaticPaths: GetStaticPaths = async () => {
const docs = getAllDocs();
return {
paths: docs.map((p) => ({
params: {
slug: getSlugs(p),
},
})),
fallback: false,
};
};
export const getStaticProps: GetStaticProps = async ({ params }) => {
let slug = params?.slug!;
if (Array.isArray(slug)) slug = slug.join("/");
const doc = await getDocBySlug(slug);
const nav = getDocsNav();
return {
props: {
doc,
nav,
},
};
};
interface Props {
doc: Doc;
nav: Record<string, Navigation[]>;
}
export default function Doc({ doc, nav }: Props) {
const { mdxSource, frontMatter } = doc;
return (
<>
<DocLayout nav={nav} frontMatter={frontMatter}>
<MDXRenderer mdxSource={mdxSource} frontMatter={frontMatter} />
</DocLayout>
</>
);
}